home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************/
- /* myActionProc C14Calculator */
- /* Called when there is a mouse click on a control part. */
- /* */
- /* Note: although the physical location of destRect doesn't change, scrolling */
- /* and autoscroll change the value of destRect.top */
- /************************************************************************************/
-
- #include "myActionProc.h"
- #ifndef __C14__
- #include "PredatorPrey.h"
- #endif
- #include "WhichWindow.h"
- #include "HelpGetProc.h"
- #include "Globals.h"
- #include <stdlib.h>
-
- void myActionSeg() {}
-
- pascal void myActionProc(ControlHandle theControl, short partCode)
- {
- int MAPRetCode;
- WindowPtr theWindow;
- TEHandle theTE;
- int vView; /* height of viewRect rounded */
- int vViewP; /* height of viewRect not rounded */
- int vLine; /* height of one line of text */
- int vTotal; /* total height of text */
- int vAmount; /* total amount that can be scroled */
- int vScrlAmt; /* scroll amount */
- div_t r; /* work area for division */
- int tAdjust; /* amount to adjust thumb scrolling */
- int teHSub; /* subscript of active TE item */
- short j;
-
- teHSub = windTbl[windSub].windTEHSub; /* set the subscript */
- /* windTEHSub was set in HelpGetProc.c */
- MAPRetCode = TRUE;
-
- theWindow = ((WindowPtr) (**theControl).contrlOwner); /* ptr to window */
- WhichWindow (theWindow, &windSub); /* subscr to table */
- theTE = windTbl[windSub].windTEH[teHSub]; /* handle to TE rec */
-
- vLine = (**theTE).lineHeight; /* height of 1 line */
- vViewP = (**theTE).viewRect.bottom -(**theTE).viewRect.top; /* height of 1 page */
- vView = (vViewP / vLine) * vLine; /* rounded to lines */
- vTotal = (**theTE).nLines * (**theTE).lineHeight; /* height whole txt */
- if ((**theTE).teLength > 0 /* if ends in c/r */
- && (*((**theTE).hText))[(**theTE).teLength-1]=='\r') /* adjust for it */
- vTotal += (**theTE).lineHeight;
-
- switch (partCode)
- {
- case (inUpButton):
- vScrlAmt = ((**theTE).viewRect.top > (**theTE).destRect.top + vLine)
- ? vLine
- : (**theTE).viewRect.top - (**theTE).destRect.top;
- if (vScrlAmt < 0) /* if calculation has wrong sign */
- vScrlAmt = 0; /* don't scroll */
- break;
-
- case (inPageUp):
- vScrlAmt = ((**theTE).viewRect.top > (**theTE).destRect.top + vView)
- ? vView
- : (**theTE).viewRect.top - (**theTE).destRect.top;
- if (vScrlAmt < 0) /* if calculation has wrong sign */
- vScrlAmt = 0; /* don't scroll */
- break;
-
- case (inPageDown):
- vScrlAmt = ((**theTE).viewRect.bottom
- < (**theTE).destRect.top + vTotal - vView)
- ? -vView
- : -((**theTE).destRect.top + vTotal - (**theTE).viewRect.bottom);
- if (vScrlAmt > 0) /* if calculation has wrong sign */
- vScrlAmt = 0; /* don't scroll */
- break;
-
- case (inDownButton):
- vScrlAmt = ((**theTE).viewRect.bottom
- < (**theTE).destRect.top + vTotal - vLine)
- ? -vLine
- : -((**theTE).destRect.top + vTotal - (**theTE).viewRect.bottom);
- if (vScrlAmt > 0) /* if calculation has wrong sign */
- vScrlAmt = 0; /* don't scroll */
- break;
-
- case (inThumb):
- /* current value of control */
- j = GetCtlValue (theControl); /* after moving thumb */
-
- /* difference in control value */
- vScrlAmt = kkk; /* due to moving thumb */
-
- /* how much more or less than whole */
- r = div (vScrlAmt, vLine); /* number of lines in the scroll? */
-
- /* compute adjustment to the scroll */
- /* amount and the control value */
- /* to result in only scrolling a */
- /* whole number of lines */
-
- if (fabs(r.rem) < vLine/2) /* if we should round down */
- tAdjust = -r.rem; /* use this */
- else /* else */
- { /* if we should round up */
- if (r.rem > 0) /* if we are scrolling up */
- tAdjust = -r.rem + vLine; /* use this */
- else /* else if scrolling down */
- tAdjust = -r.rem - vLine; /* use this */
- }
-
- vScrlAmt += tAdjust; /* adjust scroll amt (scroll later) */
-
- if (tAdjust != 0) /* adjust control amount and redraw */
- SetCtlValue (theControl, (j - tAdjust));
- break;
-
- case (0):
- vScrlAmt = 0;
- /* If the total vertical length of */
- /* the text now is less than the */
- /* height of the viewRect, prepare */
- /* to scroll to the top of viewRect */
- if ((vViewP >= vTotal)
- && ((**theTE).viewRect.top != (**theTE).destRect.top))
- vScrlAmt = (**theTE).viewRect.top - (**theTE).destRect.top;
- break;
-
- default:
- return /*MAPRetCode*/;
- }
-
- TEScroll (0, vScrlAmt, theTE); /* do the scroll */
-
- vAmount = (vTotal > vViewP) ? vTotal-vViewP : 0; /* ..max scrollable amt */
- if (vAmount == 0) /* ..if view > text */
- (**theTE).destRect.top = (**theTE).viewRect.top; /* .. fit all in view */
-
- if (GetCtlMax (theControl) != vAmount) /* set max to.. */
- SetCtlMax(theControl, vAmount); /* .. max scrollable */
-
- if (partCode != inThumb) /* reset and redraw */
- SetCtlValue (theControl, ((**theTE).viewRect.top) - (**theTE).destRect.top);
-
- return /*MAPRetCode*/;
- }
-